//----------------------------------------------------------------------------
// M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S
//----------------------------------------------------------------------------
// Copyright (C) 2009 - MARIN - All rights reserved - http://www.marin.nl
//----------------------------------------------------------------------------
// Program    : various
// Module     : various
// File       : assertplus.h
// -----------------------------------------------------------------------------

#pragma once

#include <stdlib.h>
#include <iostream>
#include <sstream>

#ifdef DEBUG

// can be replaced by other means of output
inline void _assertDebugOut(const char *s)
{
    std::cerr << s;
}

#define DEBUGMSG(out); \
        { \
            std::ostringstream ostr; \
            _assertDebugOut(((std::ostringstream &)(ostr << \
                            out << " (" \
                            __FILE__ << ":" << __LINE__ << ")\n")).str().c_str()); \
        }

#define ASSERT(b, out); \
        if (!(b)) \
        { \
            std::ostringstream ostr; \
            _assertDebugOut(((std::ostringstream &)(ostr << \
                            "Assertion failed " << \
                            "[" << #b << "] " << out << " (" << \
                            __FILE__ << ":" << __LINE__ << ")\n")).str().c_str()); \
            exit(-1); \
        }

#define ASSERTFALSE(); \
        std::ostringstream ostr; \
        _assertDebugOut(((std::ostringstream &)(ostr << \
                        "Should never get here " << " (" << \
                        __FILE__ << ":" << __LINE__ << ")\n")).str().c_str()); \
        exit(-1);

#define ASSERTPOINTER(p); \
        if (!(p)) \
        { \
            std::ostringstream ostr; \
            _assertDebugOut(((std::ostringstream &)(ostr << \
                            "Invalid pointer " << \
                            "[" << #p << "] (" << \
                            __FILE__ << ":" << __LINE__ << ")\n")).str().c_str()); \
            exit(-1); \
        }

#else // !DEBUG

#define DEBUGMSG(out); ;
#define ASSERT(b, out); ;
#define ASSERTFALSE(); ;
#define ASSERTPOINTER(p); ;

#endif // !DEBUG
